`
https://leetcode.cn/problems/implement-queue-using-stacks/
`


var MyQueue = function () {
  // 使用两个栈模拟队列
  this.s1 = []
  this.s2 = []
};

/** 
* @param {number} x
* @return {void}
*/
MyQueue.prototype.push = function (x) {
  // 新入队元素压入 s1
  this.s1.push(x)
};

/**
* @return {number}
*/
MyQueue.prototype.pop = function () {
  // 调用 peek 保证 s2 不为空
  this.peek()
  // 返回 s2 的栈顶元素
  return this.s2.pop()
};

/**
* @return {number}
*/
MyQueue.prototype.peek = function () {
  // s2 里没有元素就把 s1 的全部出栈再压入 s2
  if (this.s2.length === 0) {
    while (this.s1.length) {
      this.s2.push(this.s1.pop())
    }
  }
  // 返回 s2 的栈顶元素
  return this.s2[this.s2.length - 1]
};

/**
* @return {boolean}
*/
MyQueue.prototype.empty = function () {
  // 两个栈都为空才为空
  return this.s1.length === 0 && this.s2.length === 0
};

/** 
* Your MyQueue object will be instantiated and called as such:
* var obj = new MyQueue()
* obj.push(x)
* var param_2 = obj.pop()
* var param_3 = obj.peek()
* var param_4 = obj.empty()
*/